home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickTime™ VR 2.0 SDK / QTVR C⁄C++ Runtime API / Sample Code / QTVRSamplePlayer / src / event.c < prev    next >
Encoding:
Text File  |  1997-05-22  |  2.9 KB  |  190 lines  |  [TEXT/CWIE]

  1. // Event handling code
  2.  
  3. // Application-specific headers
  4. #include "app.h"
  5.  
  6. // API headers
  7. #include "qtvrsupp.h"
  8.  
  9. // System headers
  10. #include <AppleEvents.h>
  11. #include <movies.h>
  12.  
  13.  
  14. /////
  15. //
  16. // Local data structures
  17. //
  18. /////
  19.  
  20.  
  21. /////
  22. //
  23. // Local Prototypes
  24. //
  25. /////
  26.  
  27. // xxx
  28. void DoMouseDown(EventRecord *theEvent);    // Handle MouseDown events
  29. void DoUpdate(EventRecord *theEvent);        // Handle Update events
  30. void DoMenuChoice(long menuResult);            // Handle Menu selections
  31. void DoKeypress(char CharCode, char KeyCode);    // Handle Keypresses
  32.  
  33. void DoNull();
  34.  
  35.  
  36. /////
  37. //
  38. // The main event-processing loop
  39. //
  40. /////
  41.  
  42. void EventLoop()
  43. {
  44.     char            charCode, keyCode;
  45.     EventRecord        theEvent;
  46.  
  47.     while (g.Done == false)
  48.         {
  49.         WaitNextEvent(everyEvent, &theEvent, nil, nil);
  50.             
  51.         if (!CheckMovieControllers(&theEvent))
  52.             {
  53.             switch (theEvent.what)
  54.                 {
  55.                 case kHighLevelEvent:
  56.                     AEProcessAppleEvent(&theEvent);
  57.                     break;
  58.                 case nullEvent:
  59.                     DoNull();
  60.                     break;
  61.                 case mouseDown:
  62.                     DoMouseDown(&theEvent);
  63.                     break;
  64.                 case keyDown:
  65.                 case autoKey:
  66.                     charCode = theEvent.message & charCodeMask;
  67.                     keyCode = (theEvent.message & keyCodeMask) >> 8;
  68.                     if ((theEvent.modifiers & cmdKey) != 0) {
  69.                         DoMenuSetup();
  70.                         DoMenuChoice(MenuKey(charCode));
  71.                     } else
  72.                         DoKeypress(charCode, keyCode);
  73.                     break;
  74.                 case activateEvt:
  75.                     break;
  76.                 case updateEvt:
  77.                     DoUpdate(&theEvent);
  78.                     break;
  79.                 }
  80.             }
  81.             
  82.         }
  83.     
  84. }
  85.  
  86.  
  87. /////
  88. //
  89. // Handle MouseDown events
  90. //
  91. /////
  92.  
  93. void DoMouseDown(EventRecord *theEvent)
  94. {
  95.     WindowPtr    whichWindow;
  96.     short int    thePart;
  97.     long int    menuChoice;
  98.  
  99.     thePart = FindWindow(theEvent->where, &whichWindow);
  100.     
  101.     
  102.     switch (thePart)
  103.     {
  104.         case inMenuBar:
  105.             DoMenuSetup();
  106.             menuChoice = MenuSelect(theEvent->where);
  107.             DoMenuChoice(menuChoice);
  108.             break;
  109.         case inSysWindow:
  110.             SystemClick(theEvent, whichWindow);
  111.             break;
  112.         case inDrag:
  113.             SelectWindow(whichWindow);
  114.             DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
  115.             break;
  116.         case inGrow:
  117.             break;
  118.         case inZoomIn:
  119.         case inZoomOut:
  120.             
  121.             break;
  122.         case inGoAway:
  123.             if(TrackGoAway(whichWindow, theEvent->where))
  124.                 CloseMovieByWindow(whichWindow);
  125.             break;
  126.         case inContent:
  127.             if (whichWindow != FrontWindow())
  128.                   SelectWindow(whichWindow);
  129.                 break;
  130.     
  131.     }    
  132. }
  133.  
  134.  
  135. /////
  136. //
  137. // Handle Keypresses
  138. //
  139. /////
  140.  
  141. void DoKeypress(char CharCode, char KeyCode)
  142. {
  143.     Boolean        CharHandled = true;
  144.  
  145.     // If <modifier(s)>
  146.     switch(CharCode) {
  147.     //    case <case>:
  148.         default:
  149.             CharHandled = false;
  150.             break;
  151.     }
  152.  
  153.     if (!CharHandled)
  154.         CharHandled = mQTVRDoKeypress(CharCode, KeyCode);
  155.  
  156.     // etc...
  157. //    if (!CharHandled)
  158. //        CharHandled = mQTVRDoKeypress(CharCode, KeyCode, EventType);
  159.  
  160. }
  161.  
  162. /////
  163. //
  164. // Handle Update events
  165. //
  166. /////
  167.  
  168. void DoUpdate(EventRecord *theEvent)
  169. {
  170.  
  171.     CWindowPtr    whichWindow;
  172.     
  173.     whichWindow = (CWindowPtr)theEvent->message;
  174.     SetGWorld(whichWindow, nil);
  175.     BeginUpdate((WindowPtr)whichWindow);
  176.     
  177.     EndUpdate((WindowPtr)whichWindow);
  178. }
  179.  
  180.  
  181. void DoNull()
  182. {
  183.     MyMoviesTask(FrontWindow());
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.